package com.adingxiong.cft.result;

/**
 * @ClassName Result
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/5/21 17:23
 **/
public class Result<T> {

    public long code;

    private String message;

    private T data;

    protected Result(){

    }
    
    protected Result(long code ,String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    public static <T> Result<T> success(T data){
        return new Result<>(RetCode.SUCCESS.getCode(),RetCode.SUCCESS.getMessage(),data);
    }
    
    public static <T> Result<T> success(T data,String message){
        return new Result<>(RetCode.SUCCESS.getCode(),message,data);
    }

    /**
     * 失败返回结果
     * @param errorCode 错误码
     */
    public static <T> Result<T> failed(IErrorCode errorCode) {
        return new Result<T>(errorCode.getCode(), errorCode.getMessage(), null);
    }

    /**
     * 失败返回结果
     * @param errorCode 错误码
     * @param message 错误信息
     */
    public static <T> Result<T> failed(IErrorCode errorCode,String message) {
        return new Result<T>(errorCode.getCode(), message, null);
    }

    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> Result<T> failed(String message) {
        return new Result<T>(RetCode.FAILED.getCode(), message, null);
    }

    /**
     * 失败返回结果
     */
    public static <T> Result<T> failed() {
        return failed(RetCode.FAILED);
    }

    /**
     * 参数验证失败返回结果
     */
    public static <T> Result<T> validateFailed() {
        return failed(RetCode.VALIDATE_FAILED);
    }

    /**
     * 参数验证失败返回结果
     * @param message 提示信息
     */
    public static <T> Result<T> validateFailed(String message) {
        return new Result<T>(RetCode.VALIDATE_FAILED.getCode(), message, null);
    }

    /**
     * 未登录返回结果
     */
    public static <T> Result<T> unauthorized(T data) {
        return new Result<T>(RetCode.UNAUTHORIZED.getCode(), RetCode.UNAUTHORIZED.getMessage(), data);
    }

    /**
     * 验证码错误
     * @param
     * @param <T>
     * @return
     */
    public static <T> Result<T> imgcodeError(){
        return new Result<T>(RetCode.VALIEDFAIL.getCode(), RetCode.VALIEDFAIL.getMessage(),null);
    }

    /**
     * 未授权返回结果
     */
    public static <T> Result<T> forbidden(T data) {
        return new Result<T>(RetCode.FORBIDDEN.getCode(), RetCode.FORBIDDEN.getMessage(), data);
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }



}